import request from '@/utils/request'

// 获取班级信息
export function getGradelist(params) {
  return request({
    url: '/api/grades/paging',
    method: 'get',
    params,
  })
}

// 添加班级
export function addGrade(data) {
  return request({
    url: '/api/grades/add',
    method: 'post',
    data,
  })
}

// 编辑班级
export function editGrade(data) {
  return request({
    url: `/api/grades/update/${data.id}`,
    method: 'put',
    data: data.newGrade,
  })
}

// 删除班级
export function deleteGrade(id) {
  return request({
    url: `/api/grades/delete`,
    method: 'delete',
    params: {
      ids: id
    }
  })
}

// 批量删除班级
export function batchDeleteGrade(ids) {
  // 使用URLSearchParams构建参数
  const searchParams = new URLSearchParams()

  // 为每个id添加一个ids参数
  ids.forEach((id) => {
    searchParams.append('ids', id)
  })

  // 将URLSearchParams转换为字符串
  const queryString = searchParams.toString()

  return request({
    url: `/api/grades/delete`,
    method: 'delete',
    params: {},
    paramsSerializer: () => queryString,
  })
}
